package com.cadre.web.controller.officer;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cadre.common.utils.R;
import com.cadre.common.utils.annotation.SysLog;
import com.cadre.common.utils.common.GenerateUUID;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.system.domain.officer.PxRypxxxEntity;
import com.cadre.system.service.A01Service;
import com.cadre.system.service.PxRypxxxService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RequestMapping({"/person/pxrypxxx"})
@RestController
/* loaded from: PxRypxxxController.class */
public class PxRypxxxController {
    @Autowired
    private PxRypxxxService pxRypxxxService;
    @Autowired
    private A01Service a01Ser;

    @PostMapping({"/impExcel"})
    @ApiOperation("导入---excel")
    @ResponseBody
    public R impExcel(@RequestParam String unitid, @RequestParam("file") MultipartFile file, HttpServletResponse response) {
        return R.ok().put("error", (Object) this.pxRypxxxService.readExcel(file, unitid));
    }

    @GetMapping({"/getListForPage"})
    @ApiOperation("培训报表查询")
    public R getListForPage(@RequestParam Map<String, Object> map) {
        if (map.get("yearStart") == null || map.get("yearEnd") == null || map.get("yearStart").toString().length() == 0 || map.get("yearEnd").toString().length() == 0) {
            map.put("qj", "");
        } else {
            map.put("qj", map.get("yearStart") + "-" + map.get("yearEnd"));
        }
        return R.ok().put("page", (Object) this.pxRypxxxService.getListForPage(map));
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r14v0 */
    /* JADX WARN: Type inference failed for: r14v1 */
    /* JADX WARN: Type inference failed for: r16v2 */
    /* JADX WARN: Type inference failed for: r0v120, types: [double] */
    /* JADX WARN: Type inference failed for: r16v4 */
    /* JADX WARN: Type inference failed for: r14v7 */
    /* JADX WARN: Type inference failed for: r16v11 */
    /* JADX WARNING: Unknown variable types count: 1 */
    @GetMapping({"/getPXbyPersonId/{personid}"})
    @ApiOperation("培训情况统计表-个人")
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public R getPXbyPersonId(@PathVariable String r6) {
        /*
        // Method dump skipped, instructions count: 895
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tdqy.cadre.modular.profess.controller.PxRypxxxController.getPXbyPersonId(java.lang.String):com.tdqy.cadre.core.utils.R");
    }

    @PostMapping({"/list"})
    @ApiOperation("list")
    public R list(@RequestParam Map<String, Object> params) {
        return R.ok().put("page", (Object) this.pxRypxxxService.queryPage(params));
    }

    @PostMapping({"/info/{flowid}"})
    @ApiOperation("info")
    public R info(@PathVariable("flowid") String flowid) {
        return R.ok().put("pxRypxxx", (Object) ((PxRypxxxEntity) this.pxRypxxxService.getById(flowid)));
    }

    @PostMapping({"/save"})
    @SysLog(value = "新增干部培训信息", target = "A01", set = "PX_RYPXXX", type = 0)
    @ApiOperation("save")
    public R save(@RequestBody PxRypxxxEntity pxRypxxx) {
        if (pxRypxxx.getKsrq().compareTo(pxRypxxx.getJzrq()) > 0) {
            return R.error("开始时间大于结束时间");
        }
        pxRypxxx.setFlowid(GenerateUUID.getUUID());
        this.pxRypxxxService.save(pxRypxxx);
        return R.ok();
    }

    @PostMapping({"/update"})
    @SysLog(value = "修改干部培训信息", target = "A01", set = "PX_RYPXXX", type = 1)
    @ApiOperation("update")
    public R update(@RequestBody PxRypxxxEntity pxRypxxx) {
        if (pxRypxxx.getKsrq().compareTo(pxRypxxx.getJzrq()) > 0) {
            return R.error("开始时间大于结束时间");
        }
        this.pxRypxxxService.updateById(pxRypxxx);
        return R.ok();
    }

    @PostMapping({"/delete"})
    @SysLog(value = "删除干部培训信息", target = "A01", set = "PX_RYPXXX", type = DateUtil.SUB_MONTH)
    @ApiOperation("delete")
    public R delete(@RequestBody String[] flowids) {
        this.pxRypxxxService.removeBatchByIds(Arrays.asList(flowids));
        return R.ok();
    }

    /* JADX DEBUG: Failed to insert an additional move for type inference into block B:35:0x0138 */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r9v3 */
    /* JADX WARN: Type inference failed for: r0v45 */
    /* JADX WARN: Type inference failed for: r0v51, types: [double] */
    /* JADX WARN: Type inference failed for: r9v5 */
    /* JADX WARN: Type inference failed for: r0v66 */
    /* JADX WARN: Type inference failed for: r0v67 */
    /* JADX WARN: Type inference failed for: r0v68 */
    @GetMapping({"/listByPersonid/{personId}"})
    @ApiOperation("根据人员查询培训信息")
    public R list(@PathVariable String personId) {
        List<PxRypxxxEntity> list = this.pxRypxxxService.getBaseMapper().selectList(
                new LambdaQueryWrapper<PxRypxxxEntity>().eq(PxRypxxxEntity::getPersonid, personId));//todo:需要加上排序.orderBy("KSRQ", false).orderBy("JZRQ", false));
        List<PxRypxxxEntity> listNew = new ArrayList<>();
        //在新的集合中添加数据，并且根据list中的pxnd字段计算当前年度的xs总数是多少并且赋值在所有同年度下的ndxs字段中
       list.stream().forEach(item -> {
           PxRypxxxEntity pxRypxxxEntity = new PxRypxxxEntity();
           BeanUtil.copyProperties(item, pxRypxxxEntity);
           //计算list中pxnd等于pxRypxxxEntity的pxnd字段的，xs字段的总数
           Double sum = list.stream()
                   .filter(entity -> entity.getPxnd().equals(pxRypxxxEntity.getPxnd()))
                   .mapToDouble(PxRypxxxEntity::getXs)
                   .sum();
           pxRypxxxEntity.setNdxs(sum);
           listNew.add(pxRypxxxEntity);
       });
        return R.ok().put("data", (Object) listNew);
    }

    @GetMapping({"/getRole/{userId}"})
    @ApiOperation("根据用户id获取权限")
    public R getRole(@PathVariable String userId) {
        return R.ok().put("flag", (Object) this.pxRypxxxService.getRole(userId, "培训管理"));
    }

    @PostMapping({"/exportPxRypxxx"})
    @ApiOperation("导入PxRypxxx")
    public R editPxRypxxx(@RequestBody List<PxRypxxxEntity> list) {
        if (list.size() > 0) {
            for (int n = 0; n < list.size(); n++) {
                this.pxRypxxxService.save(list.get(n));
            }
        }
        return R.ok();
    }
}
